<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>找回密码</title>
</head>
<script src="../../js/edition.js"></script> 
<link rel="stylesheet" href="../../css/base.css">
<script>
        document.write("<l"+"ink rel='stylesheet' href='../../css/style.css?version="+edition+"'>")
</script>
<script>
        document.write("<l"+"ink rel='stylesheet' href='../../css/popover.css?version="+edition+"'>")
</script>
<script src="../../js/jquery.js"></script>
<script src="../../js/template.js"></script>
<script> 
        document.write("<s"+"cript type='text/javascript' src='../../js/url.js?version="+edition+"'></scr"+"ipt>"); 
</script>
<script src="../../js/login_foot.js"></script>
<script src="../../js/login_header.js"></script>
<script src="../../js/popover.js"></script>
<body>
    <div class="header_t">
		<script>
			$(function(){
				login_header();
				$('.header_bg .fl_r').html('<a href="login.html?type=1" style="color:#333;">返回登录&gt;&gt;</a>')
				$('.header_bg .fl_r').css({
					'border':'none',
					'text-align':'right',
				}); 
			}); 
		</script>
    </div>
    <form action="" method="post" class="register_tab">
        <div class="register_bg" style="padding-top:0px;">
			<p class="login_title">找回密码</p>
			<ul>
				<li>
					<em>手机号码</em>
					<input type="text" name="phone" id="phone" placeholder="请输入手机号码">
					<div class="error">请输入手机号码</div>
				</li>
				<li>
					<em>验<i style="width: 6px; display: inline-block;"></i>证<i style="width: 6px; display: inline-block;"></i>码</em>
					<input type="text" name='phoneCode' id="verification" placeholder="请输入验证码">
					<a id="phoneCode">获取短信验证码</a>
					<a style="display:none" class="phoneCode"></a>
					<div class="error">验证码错误</div>
				</li>
				<li>
					<em>密<i style="width: 24px; display: inline-block;"></i>码</em>
					<input type="password" maxlength="18" name="newPassword" id="password" placeholder="请输入密码">
					<div class="error">请输入最少6位数的密码</div>
				</li>
			</ul>
			<div class="login_sub"  style="width:364px;"><input type="submit"  style="width:364px;" value="提交" id="login_sub"></div> 
        </div>        
    </form>
    <div class="login_foot" id="login_foot">
	<script>
		$(function(){
			login_foot();
		});
	</script>
    </div>
</body>
<script>
    function ajax_form(){ 
        $('#phoneCode').click(function(){ 
			var phone = $('#phone').val(); // 获取手机号
			var url= new_url+"shop/login/sendPhoneCode"; 
			var time='60'; 
			function tim(){
				setTimeout(function(){                                               
					if(time>'0'){
						tim();
						time --
						$('#phoneCode').hide(); 
						$('.phoneCode').show(); 
						$('.phoneCode').text(time+'s重新获取'); 
					}else{ 
						$('.phoneCode').hide(); 
						$('#phoneCode').show(); 
						$('#phoneCode').text('重新获取验证码'); 
					}    
				},1000);
			}
			if((/^1(3|4|5|7|8)\d{9}$/.test(phone))){
				tim();
				$.ajax({
					type: "post",
					dataType:'json',
					url: url, 
					data:'phone='+phone,       
					success: function(e){
						// console.info(e)
						if(e.code=='0'){
							tc(e.message);
						}
						else{
							tc(e.message);
						}
					}
				});
			}else{
				tc('请输入手机号');
			}
        });       
		function phone(){               
			var phone = $('#phone').val();
			if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){
				$('#phone').parents('li').addClass('error_bor');
				$('.error_bor').find('.error').show(); 
				return false;    
			}else{
				$('#phone').parents('li').removeClass('error_bor');
				$('#phone').parents('li').find('.error').hide();
			};    
			if($('#verification').val()==''){
				$('#verification').parents('li').addClass('error_bor'); 
				$('.error_bor').find('.error').show();
				return false; 
			}else{
				$('#verification').parents('li').removeClass('error_bor');
				$('#verification').parents('li').find('.error').hide()
			};
			if($('#password').val().length<6){
				$('#password').parents('li').addClass('error_bor');
				$('.error_bor').find('.error').show();
				return false; 
			}else{
				$('#password').parents('li').removeClass('error_bor');
				$('#password').parents('li').find('.error').hide()
			};           
		}
		$('#login_sub').on('click',function(){
			phone(); 
			if($('.register_bg ul li').hasClass('error_bor')){
				return false;
			}else{
				$.ajax({
					type:'post',
					dataType: 'json',
					data:$(".register_tab").serialize(),
					url:new_url+'shop/login/findPassword',
					success:function(e){
						// console.info(e)
						if(e.code=='0'){
							tc(e.message);
							setTimeout(function(){
								window.location.href='/src/login/login.html?type=1'
							},1000)
						}
						else{
							tc(e.message);
						}
					},
				}); 
				return false;
			}
		});
    }ajax_form();
</script>

</html>